﻿@using Microsoft.AspNetCore.Mvc.Localization
@using Skoruba.IdentityServer4.Admin.BusinessLogic.Shared.Dtos.Common
@model Skoruba.IdentityServer4.Admin.BusinessLogic.Identity.Dtos.Identity.Interfaces.IUserRolesDto
@inject IViewLocalizer Localizer

@{
	ViewBag.Title = Localizer["Title"];
	Layout = "_Layout";
}

<form asp-controller="Identity" asp-action="UserRoles" Method="post">
	<div class="row">
		
		<div class="col-12">
			<nav aria-label="breadcrumb">
				<ol class="breadcrumb">
					<li class="breadcrumb-item"><a asp-controller="Identity" asp-action="Users">@Localizer["NavigationUsers"]</a></li>
					<li class="breadcrumb-item"><a asp-controller="Identity" asp-action="UserProfile" asp-route-id="@Model.UserId">@Model.UserName</a></li>
					<li class="breadcrumb-item active" aria-current="page">@Localizer["Title"]</li>
				</ol>
			</nav>
		</div>

		<div class="col-md-12">
			<h3>@Localizer["Title"]</h3>

			<div asp-validation-summary="All" class="text-danger"></div>

			<!--Hidden -->
			<input type="hidden" asp-for="UserId"/>

			<div class="card mt-3">
				<h5 class="card-header">@Localizer["SubTitle"]</h5>
				<div class="card-body">

					<!--Select-->
					<div class="form-group row">
						<label asp-for="RoleId" class="col-sm-3 col-form-label">
							@await Html.PartialAsync("User/Section/Label", "RolesList")
						</label>
						<div class="col-sm-9">
							<select asp-for="RoleId" asp-items="@(new SelectList(Model.RolesList, "Id", "Text"))" class="form-control single-select"></select>
						</div>
					</div>

					<!--Button-->
					<div class="form-group row">
						<label class="col-sm-3 col-form-label">
						</label>
						<div class="col-sm-9">
							<button type="submit" class="btn btn-primary">@Localizer["ActionAddRole"]</button>
						</div>
					</div>
				</div>
			</div>

		</div>
	</div>
</form>

<div class="row">
	<div class="col-md-12">
		<div class="card mt-3">
			<h5 class="card-header">@Localizer["TitleRoles"]</h5>
			<div class="card-body">

				<div class="row table-responsive">
					<table class="table table-striped">
						<thead>
							<tr>
								<th>@Localizer["RoleName"]</th>
								<th></th>
							</tr>
						</thead>
						<tbody>
							@foreach (var role in Model.Roles)
							{
								<tr>
									<td>@role.Name</td>
									<td><a asp-action="UserRolesDelete" asp-route-roleId="@role.Id" asp-route-id="@Model.UserId" class="btn btn-danger">@Localizer["ActionRemoveRole"]</a></td>
								</tr>
							}
						</tbody>
					</table>
				</div>

				<div class="row">
					<div class="col-12">
						@await Html.PartialAsync("Common/Pager", new Pager { Action = "UserRoles", PageSize = Model.PageSize, TotalCount = Model.TotalCount })
					</div>
				</div>
			</div>
		</div>
	</div>
</div>